#include<stdio.h>
#define Len 8

int a[Len] = {5, 2, 4, 7, 1, 3, 2, 6};


int partition(int start, int end)
{
  int pivot = a[start];
  int small[Len];
  int big[Len];
  
  int i, j = 0, k = 0;
  for (i = start; i <= end; ++i){
    if (a[i] < pivot){
      small[j++] = a[i];
    }
    else{
      big[k++] = a[i];
    }
  }

  int mid = start + j;

  int n = 0;
  for (i = start; i < start + j; ++i){
    a[i] = small[n++];
  }

  int m = 0;

  for (i = start + j; i < start + j + k; ++i){
    a[i] = big[m++];
  }

  return mid;
}

void quicksort(int start, int end)
{
  int mid;
  if (end > start){
    mid = partition(start, end);
    quicksort(start, mid);
    quicksort(mid + 1, end);
  }
}

int main()
{
  quicksort(0, 7);
  int i;
  for (i = 0; i < Len; ++i){
    printf("%d ", a[i]);
  }
  printf("\n");
}
